package com.zjhome.cloudnote.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import lombok.AllArgsConstructor;

/**
 * 401异常 自定义处理
 * 
 * @author 0283000121
 *
 */
@AllArgsConstructor
public class Http401AuthenticationEntryPoint implements AuthenticationEntryPoint {
	private final String headerValue;

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException authException) throws IOException, ServletException {
		// 
		response.setHeader("Authorization", this.headerValue);
		response.sendError(HttpServletResponse.SC_UNAUTHORIZED, 
				authException.getMessage()
		);
		
	}

}
